import * as THREE from "three";
import Sizes from "./Utils/Sizes";
import Time from "./Utils/Time";
import Camera from "./Camera";
import Renderer from "./Renderer";
import World from "./World/World";
import Resources from "./Utils/Resources";
import sources from "./sources";
export default class Experience {
  static instance; //类身上设置静态属性，用于单例挂载。
  constructor(canvas) {
    if (Experience.instance) return Experience.instance;
    Experience.instance = this;

    // globalThis.experience = this;

    this.canvas = canvas;
    this.scene = new THREE.Scene();
    this.sizes = new Sizes();
    this.time = new Time();
    this.camera = new Camera();
    this.renderer = new Renderer();
    this.resources = new Resources();
    this.world = new World();

    this.sizes.on("resize", this.resize.bind(this));
    this.time.on("tick", this.update.bind(this));//当time身上的tick被触发，就执行update方法。相当于随着时间变化，update函数也要对应触发。

  }

  resize() {
    this.camera.resize();
    this.renderer.resize()
  }

  update() {
    this.camera.update();
    this.renderer.update();
  }
}
